<?php

defined('BY_JYA') or exit('error');
list($params)=$arguments;

		$card_id = $params['card_id'];
		$card_type = $params['card_type'];
		$logo_url = $params['wxlogourl'];
		//$color = $params['color'];
		$notice = $params['notice'];
		$service_phone = $params['service_phone'];
		$description = $params['description'];
		$type = $params['datetype'];
		if ($type == '1') {
			$begin_timestamp = $params['begin_timestamp'];
			$end_timestamp = $params['end_timestamp'];
		}

		$use_limit = (empty($params['use_limit']) ? 1 : $params['use_limit']);
		$get_limit = (empty($params['get_limit']) ? 1 : $params['get_limit']);
		$can_share = (empty($params['can_share']) ? 'false' : 'true');
		$can_give_friend = (empty($params['can_give_friend']) ? 'false' : 'true');
		$center_title = $params['center_title'];
		$center_sub_title = $params['center_sub_title'];
		$center_url = $params['center_url'];
		$setcustom = $params['setcustom'];

		if (!empty($setcustom)) {
			$custom_url_name = $params['custom_url_name'];
			$custom_url_sub_title = $params['custom_url_sub_title'];
			$custom_url = $params['custom_url'];
		}

		$setpromotion = $params['setpromotion'];

		if (!empty($setpromotion)) {
			$promotion_url_name = $params['promotion_url_name'];
			$promotion_url_sub_title = $params['promotion_url_sub_title'];
			$promotion_url = $params['promotion_url'];
		}

		if ($card_type == 'MEMBER_CARD') {
			$activate_url = $params['activate_url'];
			$background_pic_url = $params['background_pic_url'];
			$prerogative = $params['prerogative'];
			$custom_field1 = $params['custom_field1'];

			if (!empty($custom_field1)) {
				$custom_field_name_type1 = $params['custom_field_name_type1'];
				$custom_field_url1 = $params['custom_field_url1'];
			}

			$custom_field2 = $params['custom_field2'];

			if (!empty($custom_field2)) {
				$custom_field_name_type2 = $params['custom_field_name_type2'];
				$custom_field_url2 = $params['custom_field_url2'];
			}

			$custom_field3 = $params['custom_field3'];

			if (!empty($custom_field3)) {
				$custom_field_name_type3 = $params['custom_field_name_type3'];
				$custom_field_url3 = $params['custom_field_url3'];
			}

			$custom_cell1 = $params['custom_cell1'];

			if (!empty($custom_cell1)) {
				$custom_cell1_name = $params['custom_cell1_name'];
				$custom_cell1_tips = $params['custom_cell1_tips'];
				$custom_cell1_url = $params['custom_cell1_url'];
			}
		}

		$jsonData = '{';
		$jsonData .= '"card_id":"' . $card_id . '"';

		if ($card_type == 'CASH') {
			$jsonData .= ',"cash":{';
		}
		else if ($card_type == 'DISCOUNT') {
			$jsonData .= ',"discount":{';
		}
		else {
			if ($card_type == 'MEMBER_CARD') {
				$jsonData .= ',"member_card":{';
				$jsonData .= '"background_pic_url":"' . $background_pic_url . '",';
			}
		}

		$jsonData .= '"base_info":{';

		if (!empty($logo_url)) {
			$jsonData .= '"logo_url":"' . $logo_url . '",';
		}

		if (!empty($color)) {
			$jsonData .= '"color":"' . $color . '",';
		}

		$jsonData .= '"notice":"' . $notice . '"';

		if (!empty($service_phone)) {
			$jsonData .= ',"service_phone":"' . $service_phone . '"';
		}

		$jsonData .= ',"description":"' . $description . '"';

		if ($type == '1') {
			$jsonData .= ',"date_info":{';
			$jsonData .= '"type":"DATE_TYPE_FIX_TIME_RANGE"';
			$jsonData .= ',"begin_timestamp":' . $begin_timestamp;
			$jsonData .= ',"end_timestamp":' . $end_timestamp;
			$jsonData .= '}';
		}

		$jsonData .= ',"use_limit":' . $use_limit;
		$jsonData .= ',"get_limit":' . $get_limit;
		$jsonData .= ',"can_share":' . $can_share;
		$jsonData .= ',"can_give_friend":' . $can_give_friend;
		$jsonData .= ',"center_title":"' . $center_title . '"';
		$jsonData .= ',"center_sub_title":"' . $center_sub_title . '"';
		$jsonData .= ',"center_url":"' . $center_url . '"';

		if (!empty($setcustom)) {
			$jsonData .= ',"custom_url_name":"' . $custom_url_name . '"';
			$jsonData .= ',"custom_url":"' . $custom_url . '"';
			$jsonData .= ',"custom_url_sub_title":"' . $custom_url_sub_title . '"';
		}

		if (!empty($setpromotion)) {
			$jsonData .= ',"promotion_url_name":"' . $promotion_url_name . '"';
			$jsonData .= ',"promotion_url_sub_title":"' . $promotion_url_sub_title . '"';
			$jsonData .= ',"promotion_url":"' . $promotion_url . '"';
		}

		$jsonData .= '}';

		if ($card_type == 'MEMBER_CARD') {
			$jsonData .= ',"prerogative":"' . $prerogative . '"';

			if (!empty($custom_field1)) {
				$jsonData .= ',"custom_field1":{';
				$jsonData .= '"name_type":"' . $custom_field_name_type1 . '"';

				if (!empty($custom_field_url1)) {
					$jsonData .= ',"url":"' . $custom_field_url1 . '"';
				}

				$jsonData .= '}';
			}

			if (!empty($custom_field2)) {
				$jsonData .= ',"custom_field2":{';
				$jsonData .= '"name_type":"' . $custom_field_name_type2 . '"';

				if (!empty($custom_field_url2)) {
					$jsonData .= ',"url":"' . $custom_field_url2 . '"';
				}

				$jsonData .= '}';
			}

			if (!empty($custom_field3)) {
				$jsonData .= ',"custom_field3":{';
				$jsonData .= '"name_type":"' . $custom_field_name_type3 . '"';

				if (!empty($custom_field_url3)) {
					$jsonData .= ',"url":"' . $custom_field_url3 . '"';
				}

				$jsonData .= '}';
			}

			if (!empty($activate_url)) {
				$jsonData .= ',"activate_url":"' . $activate_url . '"';
			}

			if (!empty($custom_cell1)) {
				$jsonData .= ',"custom_cell1":{';
				$jsonData .= '"name":"' . $custom_cell1_name . '"';
				$jsonData .= ',"tips":"' . $custom_cell1_tips . '"';
				$jsonData .= ',"url":"' . $custom_cell1_url . '"';
				$jsonData .= '}';
			}
		}

		$jsonData .= '}';
		$jsonData .= '}';
		$token =  cfc('account')->getAccessToken();
		$url = 'https://api.weixin.qq.com/card/update?access_token=' . $token;
		
		$result = cfc('http')->ihttp_post($url, $jsonData);
		
		$result =@json_decode($result['content'],true);
		return $result;
